const std = @import("std");
const maxInt = std.math.maxInt;


pub const Apple = struct {
	x: u8,
	y: u8,


	pub fn generate(max_x: u8, max_y: u8, exclude: [][2]u8) Apple {
		var x: u8 = std.crypto.random.int(u8) % (max_x +| 1);
		var y: u8 = std.crypto.random.int(u8) % (max_y +| 1);

		while (_slice_contains(x, y, exclude)) {
			x +%= 1;
			y = if (x > 0) y else y +% 1;
		}

		return Apple{.x = x, .y = y};
	}


	fn _slice_contains(x: u8, y: u8, slice: [][2]u8) bool {
		for (slice) |item| {
			if (x == item[0] and y == item[1]) {
				return true;
			}
		}
		return false;
	}
};
